<template>
	<view class="navbar" :style="{height: (navH||46) +'px'}">
		<block v-if="vuiData.isBack">
			<view class="navbar-back" @click="navBack">
				<image :src="src"></image>
			</view>
		</block>
		<block v-if="vuiData.title">
			<view class='navbar-title'>{{vuiData.title}}</view>
		</block>
		<block v-if="vuiData.nav">
			<view class="navbar-flex">
				<block v-for="(it, k) in vuiData.nav" :key="k">
					<text :class="[index == k ? 'active' : '']" @click="switchNav(k)">{{it}}</text>
				</block>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		name: 'nav-bar',
		props: ['vuiData'],
		data() {
			return {
				index: 1,
				src: '',
				navH: null,
			}
		},
		mounted() {
			uni.getSystemInfo({
				success: (res) => {
					// 获取导航条高度
					let navH = res.statusBarHeight + 46;
					this.navH = navH;
				}
			});
		},
		computed: {
			iiSrc() {
				this.src = this.iSrc || '/static/back_icon.png';
			}
		},
		methods: {
			// 切换导航
			switchNav(i) {
				this.index = i;
				this.$emit('switchNav', i);
			},
			// 返回前一页
			navBack() {
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style>
	.navbar {
	  position: fixed;
	  top: 0;
	  left: 0;
	  width: 100%;
	  border-bottom: 1px solid #eee;
	  overflow: hidden;
	  background-color: #ffffff;
	  z-index: 116;
	}
	.navbar .navbar-back {
		position: absolute;
		left: 10px;
		bottom: 0;
		width: 50px;
		height: 46px;
		line-height: 46px;
		text-align: left;
		z-index: 11;
	}
	.navbar .navbar-back image {
		width: 16px;
		height: 14px;
		line-height: 46px;
	}
	.navbar .navbar-flex {
		position: absolute;
		bottom: 0;
		left: 0;
		z-index: 10;
		width: 100%;
		height: 46px;
		line-height: 46px;
	}
	.navbar .navbar-flex text {
		margin: 0 10px;
		padding-bottom: 2px;
		font-size: 30upx;
		color: #aaa;
	}
	.navbar .navbar-flex text.active {
		border-bottom: 2px solid #82d7d0;
		color: #333;
	}
	.navbar-title {
	  width: 100%;
	  height: 46px;
	  line-height: 46px;
	  text-align: center;
	  position: absolute;
	  bottom: 0;
	  left: 0;
	  z-index: 10;
	  background-color: #fff;
	  color: #333;
	  font-size: 30rpx;
	}
	
</style>